import {
    createRouter,
    createWebHistory,
    RouteRecordRaw,
} from "vue-router";
// @ts-ignore
import Login from "@/components/Login.vue";
// @ts-ignore
import Home from "@/components/backend/Home.vue";
// @ts-ignore
import AdminInfo from "@/components/backend/AdminInfo.vue";
import FoodInfo from "@/components/backend/FoodInfo.vue";
import FoodCategoryInfo from "@/components/backend/FoodCategoryInfo.vue";
import FoodInInfo from "@/components/backend/FoodInInfo.vue";
import FoodOutInfo from "@/components/backend/FoodOutInfo.vue";
import AdminRole from "@/components/backend/AdminRole.vue";
import FoodCategoryView from "@/components/backend/FoodCategoryView.vue";

const routes = [
    {
        path: "/login",
        name: "login",
        component: Login,
    }, {
        path: "/",
        name: "home",
        component: Home,
        children: [
            {
                path: "adminRole",
                name: "adminRole",
                showName: "权限管理",
                root: true,
                component: AdminRole,
            }, {
                path: "adminInfo",
                name: "adminInfo",
                showName: "管理员信息",
                component: AdminInfo,
            }, {
                path: "foodInfo",
                name: "foodInfo",
                showName: "食品信息",
                component: FoodInfo,
            }, {
                path: "foodCategory",
                name: "foodCategory",
                showName: "食品种类信息",
                component: FoodCategoryInfo,
            }, {
                path: "foodInInfo",
                name: "foodInInfo",
                showName: "入库订单",
                component: FoodInInfo,
            }, {
                path: "foodOutInfo",
                name: "foodOutInfo",
                showName: "出库订单",
                component: FoodOutInfo,
            },

            // {
            //     path: "foodCategoryView",
            //     name: "foodCategoryView",
            //     showName: "各种类食品信息",
            //     component: FoodCategoryView,
            // },


        ]
    }

];

const router = createRouter({
    history: createWebHistory(),
    routes,
});

// @ts-ignore
router.beforeEach(async (to, from, next) => {
    // 如果是登录路径就直接放行
    if (to.path == '/login') return next()

    if (window.localStorage.getItem("adminlogin") == null) return next("/login")

    next()
})
export default router;

